package main

import (
	"customer/model"
	"customer/server"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	data, _ := ioutil.ReadFile("db/data.json")
	var customers []model.Customer
	json.Unmarshal(data, &customers)
	var customerid = 0
	if len(customers) != 0 {
		customerid = customers[len(customers)-1].Cid
	}

	cs := server.CustomerServer{
		Customers:  customers,
		Customerid: customerid,
	}

	for {
		fmt.Printf("\033[1;30;35m%s\033[0m\n", `
------------------客户关系管理------------------
		1、添加客户
		2、查看客户
		3、更新客户
		4、删除客户
		5、保存
		6、退出
---------------------------------------------
`)
		var choice int
		fmt.Print("请输入你的选择：")
		fmt.Scan(&choice)

		switch choice {
		case 1:
			cs.AddCustomer()
		case 2:
			cs.ViewCustomer()
		case 3:
			cs.UpdateCustomer()
		case 4:
			cs.DeleteCustomer()
		case 5:
			cs.SaveCustomer()
		case 6:
			//退出，强制退出
			os.Exit(0)
		default:
			fmt.Println("输入不正确。")
		}
	}
}
